<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.CGFrame.struts.POJOs.Catemodeltime" %>
<%@ page import="com.CGFrame.struts.POJOs.Catemodelrel" %>
<%@ page import="com.CGFrame.struts.POJOs.Category" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html>
	<head>
		<META http-equiv=Content-Type content="text/html; charset=utf-8">
		<LINK href="../styles/stylewang.css"  type=text/css rel=stylesheet>
		<style type="text/css"></style>
		<script language=javascript>
			function modify(id){
				var cell=document.getElementById(id);
				var value=cell.firstChild.nodeValue;
				if(navigator.appName=="Microsoft Internet Explorer"){
					cell.nextSibling.innerHTML="<input type='button' value='Submit' onclick='if(checknumber(this)){submit();}'>";
					cell.innerHTML="<input type='text' name='modeltime' value="+value+">";
				}else{
					cell.nextSibling.nextSibling.innerHTML="<input type='submit' value='Submit' onClick='if(checknumber(this)){submit1("+value+");}'>";
					cell.innerHTML="<input type='text' name='modeltime' value="+value+">";
				}
			}
			
			function checknumber(but){
				if(navigator.appName=="Microsoft Internet Explorer"){
					var String=but.parentNode.previousSibling.firstChild.value;
					var Letters = "1234567890"; 
					var i; 
					var c; 
					for( i = 0; i < String.length; i ++ ){ 
						c = String.charAt( i ); 
						if (Letters.indexOf( c ) ==-1){ 
							alert("Only Number!");
							return false; 
						} 
					} 
					return true; 
				}else{
					var String=but.parentNode.previousSibling.previousSibling.firstChild.value;
					var Letters = "1234567890"; 
					var i; 
					var c; 
					for( i = 0; i < String.length; i ++ ){ 
						c = String.charAt( i ); 
						if (Letters.indexOf( c ) ==-1){ 
							alert("Only Number!");
							return false; 
						} 
					} 
					return true; 
				}
			}
			
//			function check(){
//				alert(document.all.submit.getAttribute("id");
//   			   document.all.submit.click();
//			}
			
			function submit1(value){
				alert(value);
			}
		</script>
	</head>
	<body>
		<table  border="0" width="100%" cellspacing="0" id="table1">
		<tr>
			<td width="15%" colspan="4" id="onlybt"><bean:message key="modelname"/>: <font color="#990000"><%=request.getAttribute("modelName") %></font></td>
		</tr>
		<tr>
			<td width="15%" id="btleftbian"><b>&nbsp;<bean:message key="categoryname"/></b></td>
			<td width="15%" id="btcenterbian"><b>&nbsp;<bean:message key="categorytype"/></b></td>
			<td width="15%" id="btcenterbian"><b>&nbsp;<bean:message key="expectedhours"/></b></td>
			<td width="15%" id="btrightbian">&nbsp;</td>
		</tr>
		<%
			List list=(List)request.getAttribute("list");
			for(Iterator iter=list.iterator();iter.hasNext();){
			Catemodeltime cat=(Catemodeltime)iter.next();
		%>
		<tr>
		<form action="modeltime.do" method="POST" >
			<td  width="15%" id="leftcenter"><%=cat.getCategory().getCategoryName()%></td>
			<td width="15%" id="leftcenter"><%=cat.getCategory().getCategoryType()%></td>
			<td  class="leftcenter" id="<%=cat.getCateModleTimeId()%>" width="15%" ><%=cat.getHours()%></td>
			<td id="rightcenter">
			<input type="button" value="ModifyTime" onClick="modify('<%=cat.getCateModleTimeId()%>')">
			
			<a href="delmodelcate.do?catetimeid=<%=cat.getCateModleTimeId()%>&modelId=<%=cat.getCatemodel().getCateModelId()%>" onClick="return confirm('')">[
			<bean:message key="cate.delete"/>]</a>	
			</td>
			<input type="hidden" name="catemodeltimeid" value="<%=cat.getCateModleTimeId()%>">
			<input type="hidden" name="catemodelid" value="<%=cat.getCatemodel().getCateModelId()%>">
		</form>
		</tr>
		<%}%>
		<tr>
		<form action="newmodelcate.do" method="POST">
			<td  width="15%" id="leftcenter">
				<select name="categoryId">
				<%List cates3=(List)request.getAttribute("cates");
					 for(Iterator iter=cates3.iterator();iter.hasNext();){
					 	Category cate=(Category)iter.next();
					%>
						<option value="<%=cate.getCategoryId()%>"><%=cate.getCategoryName()%>(<%=cate.getCategoryType() %>)</option>
					<%}%>
				</select>
			</td>
			<td  width="15%" id="leftcenter">&nbsp;</td>
			<td  width="15%" id="leftcenter"><input name="hours" type="text"></td>
			<td  width="15%" id="rightcenter"><input type="submit" value="Add">
				<input type="hidden" name="modelId" value="<%=request.getAttribute("modelId")%>">
				<%if(request.getAttribute("NewModelCateResult")!=null) {%><span STYLE="color:red"><%=request.getAttribute("NewModelCateResult") %></span><%} %>
				<%if(request.getAttribute("notnumber")!=null) {%><span STYLE="color:red"><%=request.getAttribute("notnumber") %></span><%} %>
			</td>
		</form>
		</tr>
		<tr><td id="tdtop" colspan="4">&nbsp;</td></tr>
		</table>
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
			<td width="15%" id="btleftbian"><bean:message key="previouscategory"/></th>
			<td width="15%" colspan="2" id="btrightbian"><bean:message key="nextcategory"/></th>
			</tr>
			<%
			List rels=(List)request.getAttribute("relations");
			for(Iterator iter=rels.iterator();iter.hasNext();){
			Catemodelrel rel=(Catemodelrel)iter.next();
			%>
			<form action="delrel.do" method="GET">
			<tr>
				<td  width="15%" id="leftcenter"><%=rel.getCategoryByCategory1id().getCategoryName()%></td>
				<td  width="15%" id="leftcenter"><%=rel.getCategoryByCategory2id().getCategoryName()%></td>
				<td   width="15%" id="rightcenter"><input type="submit" value="DELETE"></td>
				<input type="hidden" name="relid" value=<%=rel.getCateModelRelId()%>>
				<input type="hidden" name="modelId" value="<%=request.getAttribute("modelId")%>">
			</tr>
			</form>
			<%}%>
			<tr><td id="tdtop" colspan="3">&nbsp;</td></tr>
		</table>
		<form action="addrel.do" method="GET">
		<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<tr>
			  <td width="15%" id="btleftbian"><bean:message key="previouscategory"/></td>
			  <td width="15%" colspan="2" id="btrightbian"><bean:message key="nextcategory"/></td>
			</tr>
			<tr>
				<td width="15%" id="leftcenter">
					<select name="cate1">
					<%List cates1=(List)request.getAttribute("list");
					 for(Iterator iter=cates1.iterator();iter.hasNext();){
					 	Catemodeltime cate=(Catemodeltime)iter.next();
					%>
						<option value="<%=cate.getCategory().getCategoryId()%>"><%=cate.getCategory().getCategoryName()%>(<%=cate.getCategory().getCategoryType() %>)</option>
					<%}%>
					</select>
				</td>
				<td  width="15%" id="leftcenter">
					<select name="cate2">
					<%List cates2=(List)request.getAttribute("list");
					 for(Iterator iter=cates2.iterator();iter.hasNext();){
					 	Catemodeltime cate=(Catemodeltime)iter.next();
					%>
						<option value="<%=cate.getCategory().getCategoryId()%>"><%=cate.getCategory().getCategoryName()%>(<%=cate.getCategory().getCategoryType() %>)</option>
					<%}%>
					</select>
					<input type="hidden" name="modelId" value="<%=request.getAttribute("modelId")%>">
				</td>
				<td width="15%" id="rightcenter"><input type="submit" value="Add"><%if(request.getAttribute("result")!=null){%><span STYLE="color:red"><%=request.getAttribute("result")%></span><%}%></td>
			</tr>
			<TR><Td id="tdtop" colspan="3">&nbsp;</Td></TR>
		</table>
		</form>
		<input type="button" value="back" onClick="history.back();">
	</body>
</html>